/*
使用rosbag向磁盘写文件（话题+消息）
注意：编译时一定要在CMakeLists.txt里面find_pakage加入rosbag,否则编译不通过。
*/
#include "ros/ros.h"
#include "rosbag/bag.h"
#include "std_msgs/String.h"

int main(int argc, char *argv[])
{
    setlocale(LC_ALL, "");
    ros::init(argc, argv, "bag_write");
    ros::NodeHandle nh;
    std_msgs::String msg;
    msg.data = "hello xxx";
    // 1.创建rosbag对象
    rosbag::Bag bag;
    // 2.打开文件流
    bag.open("chatter.bag", rosbag::BagMode::Write);
    // 3.写bag文件
    bag.write("/chatter", ros::Time::now(), msg);
    bag.write("/chatter", ros::Time::now(), msg);
    bag.write("/chatter", ros::Time::now(), msg);
    bag.write("/chatter", ros::Time::now(), msg);
    // 4.关闭文件流
    bag.close();
    return 0;
}
